﻿using Furion.DependencyInjection;
using Furion.RemoteRequest.Extensions;
using Furion.Schedule;
using Furion.TimeCrontab;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MqttClient.Jobs
{
    [PeriodSeconds(300)]
    [JobDetail(jobId: "延时微信通知作业", description: "延时微信通知作业", GroupName = "系统", Concurrent = false)]
    public class SchoolTZJob : IJob
    {

        public SchoolTZJob(ILogger loger)
        {
            this.loger = loger;
        }
        public string server = "https://weixin.tslexunbao.com";
        private readonly ILogger loger;

        /// <summary>
        /// 校园群发通知 5分钟1次
        /// </summary>
        /// <param name="context"></param>
        /// <param name="stoppingToken"></param>
        /// <returns></returns>
        public Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
        {
            Console.WriteLine("SchoolTZJob");
            loger.Warning("电话通知 在运行");
            Scoped.Create((_, scope) =>
            {
                try
                {

                    var services = scope.ServiceProvider;
                    var response = (server + "/index.php/weixinsend/CoustomMessage").SetRequestScoped(services).GetAsStringAsync();
                    if (response.Result != "")
                    {
                        Console.WriteLine("校园通知" + response.Result);
                    }
                    response = (server + "/index.php/weixinsend/tele").SetRequestScoped(services).GetAsStringAsync();
                    if (response.Result != "")
                    {
                        Console.WriteLine("电话通知" + response.Result);
                    }

                }
                catch (Exception e)
                {

                    Console.WriteLine("校园通知 失败 " + e.Message);

                }
            });
            return Task.CompletedTask;
        }
    }
}
